﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using CodeStash.Common.DataAccess.EntityFramework;
using CodeStash.Common.Enums;

namespace CodeStash.Models.Search
{




    public class CreateSearchViewModel : IValidatableObject
    {


        #region Ctor
        public CreateSearchViewModel()
        {
            LanguageList = new List<Language>();
            VisibilityList = new List<Visibility>();
            RatingList = new List<int>();
            IncludeRating = true;
            for (int i = 1; i <= 5; i++)
            {
                RatingList.Add(i);
            }
            SearchType = CodeStash.Common.Enums.SearchType.ByKeyWord;
            CurrentPage = 1;
        }
        #endregion

 
        #region Public Properties

        public int CurrentPage { get; set;  }
        public List<Language> LanguageList { get; set; }
        public int LanguageId { get; set; }
        public List<Visibility> VisibilityList { get; set; }
        public int Visibility { get; set; }
        public string SearchForTag { get; set; }
        public string SearchForKeyWord { get; set; }
        public SearchType SearchType { get; set; }
        public bool IncludeRating { get; set; }
        public int Rating { get; set; }
        public List<int> RatingList { get; set; }
       



        #endregion

        #region IValidatableObject Members

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {

            switch (SearchType)
            {
                case Common.Enums.SearchType.ByTag:
                   if(string.IsNullOrEmpty(SearchForTag))
                        yield return new ValidationResult("Tag can't be empty", new[] { "SearchForTag" });
                    break;
                case Common.Enums.SearchType.ByKeyWord:
                   if(string.IsNullOrEmpty(SearchForKeyWord))
                        yield return new ValidationResult("Keyword can't be empty", new[] { "SearchForKeyWord" });
                    break;
                case Common.Enums.SearchType.ByLanguage:
                   if(LanguageId <= 0)
                        yield return new ValidationResult("You must enter a value for Language", new[] { "LanguageId" });
                    break;

            }

            //if(Visibility <= 0)
            //    yield return new ValidationResult("You must enter a value for Visibility", new[] { "Visibility" });
        }

        #endregion
    }

}